package ar.edu.itba.it.cg.grupo01.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.vecmath.Point3f;

import ar.edu.itba.it.cg.grupo01.api.Intersectable;
import ar.edu.itba.it.cg.grupo01.api.Intersection;
import ar.edu.itba.it.cg.grupo01.api.Intersection.Type;
import ar.edu.itba.it.cg.grupo01.api.shape.Shape;

public class IntersectionFactory {

	public Intersection<? extends Shape> emptyIntersection() {
		return new EmptyIntersection();
	}

	public Intersection<? extends Shape> createIntersection(
			Collection<Point3f> points, Shape shape) {
		return new IntersectionImpl(points, shape);
	}

	public Intersection<? extends Shape> createIntersection(
			Collection<Point3f> points, Shape shape, Intersection.Type type) {
		return new IntersectionImpl(points, shape, type);
	}

	public Intersection<? extends Shape> createIntersection(
			Set<Intersection<? extends Shape>> intersections) {

		boolean empty = true;

		for (Intersection<? extends Shape> intersection : intersections) {
			if (intersection.intersects()) {
				empty = false;
				break;
			}
		}

		return empty ? new EmptyIntersection() : new CompositeIntersection(
				intersections);
	}

	public Intersection<? extends Intersectable> createIntersectable(
			List<Point3f> points, Intersectable intersectable) {

		return new NormalIntersection(points, intersectable);
	}

	public Intersection<? extends Shape> createIntersection(
			Point3f intersectionPoint, Shape shape, Type type) {

		Collection<Point3f> points = new ArrayList<Point3f>(1);
		points.add(intersectionPoint);

		return createIntersection(points, shape, type);
	}

}
